var GameData = require('../module/gameData')();
cc.Class({
    extends: cc.Component,

    properties: {},

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.node.runAction(cc.sequence(
            cc.scaleTo(0.01,0.1),
            cc.scaleTo(0.5,1.2),
            cc.scaleTo(0.2,1),
        ))
    },
    init() {
        switch (this.node.name) {
            case "jinbi":
                this.move(50);
                break;
            case "yinbi":
                this.move(10);
                break;
            case "baoshi":
                this.move(500);
                break;
        }
    },
    move(num) {
        var pos11 = this.node.parent.convertToWorldSpaceAR(this.node.getPosition());
        var _pos1 = GameData.gameHome.node.convertToNodeSpaceAR(pos11);
        this.node.parent = GameData.gameHome.node;
        this.node.position=_pos1;

        this.node.stopAllActions();
        var _gamedata = GameData.getlocalData("fishData");
        var that = this;
        var pos2 = cc.v2(216, 280);
        var pos1 = this.node.getPosition();
        var _s = Math.sqrt(Math.pow((pos1.x - pos2.x), 2) + Math.pow((pos1.y - pos2.y), 2));
        var _t = _s / 800;
        this.node.runAction(
            cc.sequence(
                cc.spawn(
                    cc.moveTo(_t, pos2.x, pos2.y),
                    cc.scaleTo(_t, 0.5)
                ),
                cc.callFunc(function () {
                    that.node.destroy();
                    // that.node.parent.removeChild(that.node);
                    var _num1=  _gamedata.coinNum;
                    _gamedata.coinNum += num;
                    GameData.savelocalData(_gamedata);
                    GameData.gameHome.coinNum.node.parent.getComponent("gamecoin").coinAddEffect(_num1,_num1 + num);
                })
            )
        )
    },

    start() {


    },

    // update(dt) {
    //
    // },
});
